﻿Public Class FormNgOper
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Dim oper_u As String
    Public ty As String
    Public b_gt_sys_id As String
    Public current_procedure_No As Integer
    Public oper_num_all As String
    Public ng_num_all As String
    Dim objReasonMst As New clsReasonMst
    Dim objGtNgReasonDetails As New clsGtNgReasonDetails
    Private Sub FormNgOper_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        oper_u = GetIniFile("LOGIN", "user", "", g_szInitFileName)
        lbl_gt_sys_id.Text = b_gt_sys_id
        setData()
        If ty.Equals("0") Then
            objReasonMst.setMstChkList(chkNg_Reason, "gjb", current_procedure_No.ToString())
        Else
            objReasonMst.setMstChkList(chkNg_Reason, "flb", current_procedure_No.ToString())
        End If
    End Sub

    Private Sub setData()
        SpinEdit5.Value = Decimal.Parse(oper_num_all)
        SpinEdit6.Value = Decimal.Parse(ng_num_all)
        txt_operable_num.Value = SpinEdit5.Value - SpinEdit6.Value
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If txt_num.Value > 0 Then
            If txt_num.Value <= txt_operable_num.Value Then
                Dim chklstChecked As Boolean = False
                For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                    If chkNg_Reason.Items(i).CheckState = CheckState.Checked Then
                        chklstChecked = True
                    End If
                Next
                If chklstChecked = False Then
                    MsgBox("请选择不合格原因！")
                    chkNg_Reason.Select()
                    Exit Sub
                End If
                Dim ng_reason As String = String.Empty
                For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                    If chkNg_Reason.Items(i).CheckState = CheckState.Checked Then
                        ng_reason &= chkNg_Reason.Items(i).Value & "/"
                    End If
                Next
                ng_reason = ng_reason.Substring(0, ng_reason.Length - 1)
                Dim en As New entity_gt_ng_reason_details
                en.procedure_No = current_procedure_No.ToString()
                en.ng_num = Integer.Parse(txt_num.Value)
                en.ng_reason = ng_reason
                en.validity = "1"
                en.oper = oper_u
                en.b_gt_sys_id = Integer.Parse(lbl_gt_sys_id.Text)
                Dim rtn As Integer = objGtNgReasonDetails.save(en)
                If rtn <> -2 Then
                    CType(Owner, FormMain).SetDgvResultData()
                    CType(Owner, FormMain).setDgvNgOperData()
                    MsgBox("保存成功")
                    For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                        chkNg_Reason.Items(i).CheckState = CheckState.Unchecked
                    Next
                    Close()
                Else
                    MsgBox("保存失败")
                End If
            Else
                MsgBox("不合格数量>可操作数量")
            End If
        Else
            MsgBox("不合格数量需>0")
        End If
    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_num.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

End Class

Public Class entity_gt_ng_reason_details
    Public procedure_No As String   ' 工序
    Public ng_num As Integer   ' 不合格数量
    Public ng_reason As String  '原因
    Public oper As String   '操作员
    Public validity As String  '有效性
    Public b_gt_sys_id As Integer  '关联ID
End Class